package com.example.huainanlive.ui

import android.app.Activity
import android.content.Intent
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.LinearLayoutManager
import com.demon.androidbasic.base.MyActivity
import com.example.huainanlive.adapter.LiveHouseRecordAdapter
import com.example.huainanlive.databinding.ActivityLiveHouseRecordBinding

class LiveHouseRecordActivity : MyActivity<ActivityLiveHouseRecordBinding>() {

    private lateinit var huiGuLiveViewModel: HuiGuLiveViewModel
    private lateinit var liveHouseRecordAdapter: LiveHouseRecordAdapter

    //页面跳转
    companion object {
        fun forward(
            activity: Activity,
        ) {
            val intent = Intent(activity, LiveHouseRecordActivity::class.java)
            activity.startActivity(intent)
        }
    }
    override fun initBind() {
        binding = ActivityLiveHouseRecordBinding.inflate(inflater)
    }

    override fun initView() {
        huiGuLiveViewModel = ViewModelProvider(
            this)[HuiGuLiveViewModel::class.java]

        liveHouseRecordAdapter= LiveHouseRecordAdapter()
        binding.rvLiveHousePreview.layoutManager = LinearLayoutManager(activity)
        binding.rvLiveHousePreview.adapter = liveHouseRecordAdapter

        //直播回顾列表
        huiGuLiveViewModel.getLiveHouseRecord()
        huiGuLiveViewModel.getLiveHouseRecordBean.observe(this){LiveHouseRecordBean->
            liveHouseRecordAdapter.setList(LiveHouseRecordBean)
        }
        liveHouseRecordAdapter.setOnItemClickListener { _, _, position ->
            //TODO 只传了LiveId
            LivePlayActivity.forward(this, recordId = liveHouseRecordAdapter.getItem(position).recordId,
                liveState = "直播回顾")
        }

    }

}